////////////////////////////////////////////////////////////////////////
// Last svn revision: $Id:  $ 
////////////////////////////////////////////////////////////////////////

#include <math.h>
#include "MLC/Complex.hh"
#include "MLC/DefaultComplexOp.hh"

namespace drow {
namespace MLC {
namespace def {

Complex DefaultComplexOp::ComplexConjugate( const Complex& a )
{
    Complex c;
    c.Re = a.Re;
    c.Im = -a.Im;
    return c;
}

Complex DefaultComplexOp::Add( const Complex& a, const Complex& b )
{
    Complex c;
    c.Re = a.Re + b.Re;
    c.Im = a.Im + b.Im;
    return c;
}

Complex DefaultComplexOp::Subtract( const Complex& a, const Complex& b )
{
    Complex c;
    c.Re = a.Re - b.Re;
    c.Im = a.Im - b.Im;
    return c;
}

Complex DefaultComplexOp::Multiply( const Complex& a, const Complex& b )
{
    Complex c;
    c.Re = a.Re*b.Re - a.Im*b.Im;
    c.Im = a.Im*b.Re + a.Re*b.Im;
    return c;
}

double DefaultComplexOp::MagnitudeSquared( const Complex& a )
{
    return a.Re*a.Re + a.Im*a.Im;
}

double DefaultComplexOp::Magnitude( const Complex& a )
{
    return sqrt( MagnitudeSquared(a) );
}

double DefaultComplexOp::Angle( const Complex& a )
{
    return atan2( a.Im, a.Re );
}

} // namespace def
} // namespace MLC
} // namespace drow
